<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Http\Models\UserCapital;
use App\Http\Models\UserSubmitAudit;
use App\Http\Models\UserAuth;
use App\Http\Models\UserKillStatus;
use App\Http\Models\User;
use DB;

class importqq extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'import:qq';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '导入QQ列表';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //
        $qq_group = DB::table('qq_group')->get();
        foreach ($qq_group as $key => $value) {
            if ($value->avatar) {
                $upload_image = env('OLD_HTTP_URL') . $value->avatar;
                $image_url = \App\Http\Controllers\ImageController::uploadUrlImageOne($upload_image);
                $avater = $image_url ? $image_url : '';
            } else {
                $avater = '';
            }
            $user_id = User::insertGetId([
                'name' => $value->user_nicename,
                'avatar' => $avater,
                'signature' => $value->signature,
                'qq' => $value->group_num,
                'phone' => $value->group_num,
                'password' => $value->qq,
                'old_id' => $value->id,
                'created_at' => date('Y-m-d H:i:s', time())
            ]);
            UserCapital::insert([
                'voucher_number' => env('Voucher_Default_Give'),
                'user_id' => $user_id,
                'integral' => env('UserIntegral'),
                'created_at' => date('Y-m-d H:i:s', time())
            ]);
            UserSubmitAudit::insert([
                'uid' => $user_id,
                'state' => 1,
                'qq' => $value->qq,
                'created_at' => date('Y-m-d H:i:s', time())
            ]);
           /* UserAuth::insert([
                'user_id' => $user_id,
                'status' => 1,
                'channel_info' => $value->centifi_info,
                'created_at' => date('Y-m-d H:i:s', time())
            ]);*/
        }
    }
}
